package com.blackbox.price.mapper.common;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Description 封装dao层方法
 * @ClassName VisionService
 * @Author ZHOUYU
 * @Date 2019-04-08 13:46
 * @Version 1.0
 **/
@Transactional
public abstract class VisionService<T> {

    @Autowired
    private VisionMapper<T> visionMapper;

    /**
     * 保存单条
     * @param t
     * @return
     */
    public Integer save(T t){
        return visionMapper.insert(t);
    }
    /**
     * 保存list
     * @param ts
     * @return
     */
    public void save(List<T> ts){
        for (T t:ts){
            this.save(t);
        }
    }
    /**
     * 根据主键进行删除
     * @param id
     * @return
     */
    public Integer deleteById(Object id){
        return visionMapper.deleteByPrimaryKey(id);
    }
    /**
     * 根据id批量删除
     * @param ids
     * @return
     */
    public Integer deleteByIds(Object[] ids){
        return visionMapper.deleteByIds(ids);
    }
    /**
     * 主键id更新
     * @param t
     */
    public Integer update(T t) {
        return visionMapper.updateByPrimaryKey(t);
    }
    /**
     * 主键查询
     * @param id
     * @return
     */
    public T queryById(Object id){
        return visionMapper.selectByPrimaryKey(id);
    }
    /**
     * 查询所有数据
     * @return
     */
    public List<T> queryAll() {
        return visionMapper.select(null);
    }
    /**
     * 多条件是and
     * User1 user = new User1();
     * user.setUserName("java")
     * @param t
     * @return
     */
    public List<T> queryListByWhere(T t){
        return visionMapper.select(t);
    }
    /**
     * 多条件是and
     * User1 user = new User1();
     * user.setUserName("java")
     * @param t
     * @return
     */
    public void deleteByWhere(T t){
        visionMapper.delete(t);
    }

}
